import 'package:flutter/material.dart';
import './tabs/home.dart';
import './tabs/setting.dart';
class Tabs extends StatefulWidget {
  final index;
  Tabs({Key key,this.index = 0}) : super(key: key);

  _TabsState createState() => _TabsState(this.index);
}

class _TabsState extends State<Tabs> {
  int _curTabIndex = 0;
  _TabsState(index){
    this._curTabIndex = index;
  }
  List _PageList = [
    HomePage(),
    SettingPage()
  ];
  @override
  Widget build(BuildContext context) {
    return Container(
       child: Scaffold(
        appBar: AppBar(
          title: Text('Material App Bar'),
        ),
        body: this._PageList[this._curTabIndex], 
        bottomNavigationBar: BottomNavigationBar(
          currentIndex: this._curTabIndex,
          iconSize: 30.0,
          fixedColor: Colors.redAccent,
          type: BottomNavigationBarType.fixed, //设置可以放多个如果不设置最多只能放3个
          onTap:(int index){
            print(index);
            setState(() {
              this._curTabIndex = index; 
            });
          }, 
          items: [
            BottomNavigationBarItem(
              icon: Icon(Icons.home),
              title:Text("home")
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.settings),
              title:Text("Api")
            ),
          ],
        ),
      ),
    );
  }
}
